package com.huike.pmps.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huike.pmps.model.entity.PO;
import com.huike.pmps.model.entity.Supplier;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
public interface SupplierDao extends BaseMapper<Supplier> {


    /**
     * 批量插入Supplier数据
     */
    @Insert({
            "<script>",
            "insert into p_supplier(supplier_name,supplier_type_id,supplier_type_name, province_id, city_id, area_id, region, address, contacts,  phone,  email,  agreement_no,  agreement_type,  agreement_start_time,  agreement_end_time,  estimate_month_capacity, service_type_ids,service_type_names, quotation, company_profile, business_information, init_evaluation, final_evaluation,import_flag, state) values",
            "<foreach collection='supplierList' item='item' index='index' separator=','>",
            "(#{item.supplierName},#{item.supplierTypeId},#{item.supplierTypeName},#{item.provinceId},#{item.cityId},#{item.areaId},#{item.region},#{item.address}, #{item.contacts}, #{item.phone},#{item.email},#{item.agreementNo}, #{item.agreementType},#{item.agreementStartTime},#{item.agreementEndTime},#{item.estimateMonthCapacity}, #{item.serviceTypeIds},#{item.serviceTypeNames}, #{item.quotation}, #{item.companyProfile}, #{item.businessInformation},#{item.initEvaluation},#{item.finalEvaluation}, #{item.importFlag}, #{item.state})",
            "</foreach>",
            "</script>"
    })
    int insertSupplierBatch(@Param(value = "supplierList") List<Supplier> supplierList);

    @Update("UPDATE p_supplier SET number_of_courses=number_of_courses + 1 WHERE id=#{id}")
    int updateAddNumberOfCourse(Integer id);

    @Update("UPDATE p_supplier SET number_of_courses=number_of_courses - 1 WHERE id=#{id}")
    int updateMinusNumberOfCourse(Integer id);

}
